<template>
  <div class="home">
    <!-- 搜索框 -->
    <div class="title">
      <span>饿了么</span>
      <input
        type="text"
        placeholder="输入商家、商品名称"
        @click="$router.push('/index/search')"
      />
    </div>
    <!-- 背景轮播图 -->
    <div class="bg">
      <van-swipe class="my-swipe" :autoplay="2000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in bannerList" :key="index">
          <img :src="item.bannerUrl" alt="" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 猜你喜欢列表 -->
    <div class="xh">
      <p>猜你喜欢</p>
      <div class="px">
        <span v-for="(item, index) in pxArr" :key="index">{{ item }}</span>
      </div>
      <div class="rm">
        <span v-for="(item, index) in rmArr" :key="index">{{ item }}</span>
      </div>
    </div>
    <!-- 商品店铺列表 -->
    <div
      class="shop"
      v-for="(item, index) in shopList"
      :key="index"
      @click="$router.push('/details/' + item.mtWmPoiId)"
    >
      <div class="img">
        <img :src="item.picUrl" alt="" />
      </div>
      <div class="dr">
        <div class="name">
          <span>{{ item.name }}</span>
        </div>
        <div class="xs">
          <span>{{ item.wmPoiScore / 10 }}</span>
          <span>{{ item.monthSalesTip }}</span>
        </div>
        <div class="ps">
          <span>{{ item.minPriceTip }}</span>
          <span>{{ item.shippingFeeTip }}</span>
          <span>{{ item.deliveryTimeTip }}</span>
          <span>{{ item.distance }}</span>
        </div>
      </div>
    </div>
    <div class="empty"></div>
  </div>
</template>

<script>
import { banner_list, shop_list } from "../../utils/api";
export default {
  data() {
    return {
      bannerList: [],
      pxArr: ["综合排序", "距离最近", "销量最高", "筛选"],
      rmArr: ["年货节热卖", "津贴联盟", "满减优惠", "品质联盟"],
      shopList: [],
    };
  },
  mounted() {
    banner_list().then((res) => {
      // console.log(res.data);
      this.bannerList = res.data.list;
      // console.log(this.list);
    });
    shop_list().then((res) => {
      // console.log(res.data);
      this.shopList = res.data.list;
      // console.log(this.shopList);
    });
  },
};
</script>

<style lang='scss' scoped>
.title {
  background: skyblue;
  height: 100px;
  padding: 10px;
  span {
    color: white;
    font-weight: bold;
    font-size: 24px;
  }
  input {
    height: 40px;
    outline: none;
    border: none;
    border-radius: 40px;
    width: 100%;
    text-align: center;
    margin-top: 20px;
  }
}
.bg {
  padding: 10px;
  height: 60px;
  .my-swipe img {
    width: 100%;
  }
}
.xh {
  padding: 10px;
  p {
    font-size: 20px;
    font-weight: bold;
    margin: 20px 0;
  }
  .px {
    padding: 0 10px;
    display: flex;
    justify-content: space-between;
  }
  .rm {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    span {
      background: #f5f5f5;
      padding: 10px;
      font-size: 14px;
      border-radius: 5px;
    }
  }
}
.shop {
  padding: 10px;
  display: flex;
  .img {
    width: 100px;
    margin-right: 10px;
    img {
      width: 100%;
    }
  }
  .dr {
    .name span {
      font-weight: bold;
    }
    .xs {
      margin-top: 5px;
      span {
        margin-right: 10px;
      }
    }
    .ps {
      margin-top: 5px;
      span {
        margin-right: 5px;
      }
    }
  }
}
.empty {
  height: 50px;
}
</style>